package cn.com.shinho.hg.auth.modular.service.impl;

import cn.com.shinho.hg.auth.modular.entity.TbSysUser;
import cn.com.shinho.hg.auth.modular.mapper.TbSysUserMapper;
import cn.com.shinho.hg.auth.modular.model.LoginUser;
import cn.com.shinho.hg.auth.modular.service.ISysUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author Mr.Ye
 * @since 2018-07-09
 *
 * */


@Service
public class SysUserServiceImpl implements ISysUserService{


    @Autowired
    TbSysUserMapper sysUserMapper;

    @Override
    public LoginUser getUserLoginInfo(Long userId){
        TbSysUser sysUser = this.selectById(userId.intValue());
        if (sysUser != null) {
            LoginUser loginUser = new LoginUser();
            loginUser.setId(sysUser.getUserid().longValue());
            loginUser.setAccount(sysUser.getAccount());
            loginUser.setEmail(sysUser.getEmail());
            loginUser.setPhoneNumber(sysUser.getMobile());
            loginUser.setStatus(sysUser.getDeleted());
            return loginUser;
        } else {
            return null;
        }
    }

    @Override
    public TbSysUser selectById(Integer userId) {

        return sysUserMapper.selectByPrimaryKey(userId);
    }

    @Override
    public PageInfo<TbSysUser> selectAllUser() {

        Page page = PageHelper.startPage(1, 10);
        List<TbSysUser> list = sysUserMapper.selectAll();
        PageInfo<TbSysUser> p=new PageInfo<>(list);

        return p;
    }
}
